package yxy.apple.util.http;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

import yxy.apple.util.IPV4Utility;
import yxy.apple.util.NumberUtility;

public class HTTPProxy {
	protected String username = null;
	protected String password = null;
	protected int ip = 0;
	protected short port = 0;

	public HTTPProxy(String ip, short port, String username, String password) {
		this.ip = IPV4Utility.toInteger(ip);
		this.port = port;
		this.username = username;
		this.password = password;
	}

	public HTTPProxy(int ip, short port, String username, String password) {
		this.ip = ip;
		this.port = port;
		this.username = username;
		this.password = password;
	}

	public HTTPProxy(InetAddress ip, short port, String username, String password) {
		this.ip = IPV4Utility.toInteger(ip);
		this.port = port;
		this.username = username;
		this.password = password;
	}

	public InetSocketAddress getInetSocketAddress() throws UnknownHostException {
		return new InetSocketAddress(this.getInetAddress(), this.port);
	}

	public InetAddress getInetAddress() throws UnknownHostException {
		return InetAddress.getByAddress(NumberUtility.toBytes(this.ip));
	}

	public String getIPString() {
		return IPV4Utility.toString(this.ip);
	}

	public int getIPValue() {
		return this.ip;
	}

	public short port() {
		return this.port;
	}

	public String username() {
		return this.username;
	}

	public String password() {
		return this.password;
	}

	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append(this.getIPString());
		buffer.append(":");
		buffer.append(port);
		return buffer.toString();
	}
}
